<?php
/**
 * 接口引用文件
 * @author xucongbin
 */
class InterfaceFactory
{
    protected static $_interfaces = array(); 
    protected static $_requireInc = array();
    /**
     * 引入Interface文件
     * @param string $name
     * @param int $env
     * @return boolean
     */
    public static function load($name)
    {
        if (!isset(self::$_requireInc[$name])) {
            $requireFile = dirname(__FILE__) . "/libs/{$name}.php";
            if (!file_exists($requireFile)) {
            	return false;
            }
        	self::$_requireInc[$name] = require_once $requireFile;
        }   
        return true;
    }
    /**
     * 获取Interface对象实例
     * @param string $name
     * @param int $env
     * @return obj|boolean
     */
    public static function getInc($name, $env=null)
    {
        if (!isset(self::$_interfaces[$name])) {
        	if (!isset(self::$_requireInc[$name])) {
        		//throw new Exception("not include this interface file");
        		return false;
        	}
        	self::$_interfaces[$name] = new $name($env);
        }   
        if ($env) {
        	self::$_interfaces[$name]->setEnv($env);
        }        
        return self::$_interfaces[$name];
    }
}